(function () {

	//获取显示页面数据 服务器分页
    var serverData = {};
    var serverTable;
    jQuery(document).ready(function () {

    	serverTable = jQuery('#dataTable').DataTable({
            "serverSide": true,
            "ordering": false,
            "ajax": {
                "dataType": "json",
                "type": "get",
                "cache": false,
                "url":window.rootPath+ '/ui/contractQuery/getpage',
                "data": function (d) {
                    return $.extend({}, d, serverData);
                }
            },
            columns: [
                {
                	data: null
                },
                {
                    data: 'supplierCode'
                },
                {
                    data: 'orderUnit'
                },
                {
                	data: ''
                },
                {
                	data: ''
                },
                {
                	data: ''
                },
                {
                    data: 'totalSum'
                },
                {
                    data: 'signedDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD');
                        else
                            return '';
                    }
                },
                {
                    data: 'deliveryDate',
                    render: function (data, type, full, meta) {
                        if (data)
                            return moment(data).format('YYYY/MM/DD');
                        else
                            return '';
                    }
                },
                {
                	data: ''
                },
                {
                    data: ''
                }
                ],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
        
    	//查询
        jQuery('.searchBtn').on('click',function(){
        	serverData = {
        			supplierCode : jQuery('#searchContent input[name="supplierCode"]').val(),
					contractType: jQuery('#searchContent select[name="contractType"]').val(),
					minSum: jQuery('#searchContent input[name="minSum"]').val(),
					maxSum: jQuery('#searchContent input[name="maxSum"]').val(),
					startDate: jQuery('#searchContent input[name="startDate"]').val(),
					endDate: jQuery('#searchContent input[name="endDate"]').val(),
					startDate1: jQuery('#searchContent input[name="startDate1"]').val(),
					endDate1: jQuery('#searchContent input[name="endDate1"]').val(),
					outDate: jQuery('#searchContent select[name="outDate"]').val(),
					orderUnit: jQuery('#searchContent input[name="orderUnit"]').val()
				};
            serverTable.draw();
        })
        
        //撤销查询
        jQuery('.resetBtn').on("click",function()
        {
            jQuery('#supplierCode').val('');
            jQuery('#contractType').val('');
            jQuery('#minSum').val('');
            jQuery('#maxSum').val('');
            jQuery('#startDate').val('');
            jQuery('#endDate').val('');
            jQuery('#startDate1').val('');
            jQuery('#endDate1').val('');
            jQuery('#outDate').val('');
            jQuery('#orderUnit').val('');
            serverData = {};
            serverTable.draw();
        });

    });
})();